home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-09-28 | 3.5 KB | 156 lines | [TEXT/CWIE] |
- /*
- File: IOUtilities.cp
-
- Contains: QuickDraw GX to PostScript conversion code.
-
- Version: Technology: Quickdraw GX 1.1.x
-
- Copyright: © 1997 by Apple Computer, Inc., all rights reserved.
- */
-
- /*********************************
- Routine: HexBlockMove
-
- Like BlockMoveData, only convert to hex in process.
-
- srcStr: Pointer to source data to move.
- dstPtr: Pointer to destination (must be 2x in size of source)
- num: How many bytes to convert and move
-
- ***********************************/
- #include <Errors.h>
- #include <Resources.h>
- #include <Memory.h>
- #include <String.h>
- #include <Script.h>
- #include "IOUtilities.h"
-
- #define HiNybble(x) ( x >> hiNybShift )
- #define LoNybble(x) ( x & loNybMask )
- void HexBlockMove(unsigned char *srcStr, unsigned char *dstPtr, unsigned long num)
- {
- const char *hexDigits = "0123456789ABCDEF"; //Generate pc relative reference to string.
- register long hexLong = (long)hexDigits; //do this so address of string is in data register.
- register unsigned char hiNybShift = 0x04; //constants in registers for speedy operation.
- register unsigned char loNybMask= 0x0F; //constants in registers for speedy operation.
-
- if (num > 0) {
-
- do {
-
- *dstPtr++ = *(Ptr)( hexLong + HiNybble(*srcStr) );
- *dstPtr++ = *(Ptr)( hexLong + LoNybble(*srcStr) );
- ++srcStr;
-
- } while (--num);
-
- }//end if
-
-
- }//HexBlockMove
-
-
- /******
- Wrapper for NewHandle
- that returns an error.
- ******/
- OSErr PrNewHandle(Handle *h, long size)
- {
- OSErr status;
- *h = NewHandle(size);
- status = MemError();
- return status;
- }
-
- OSErr PrNewHandleClear(Handle *h, long size)
- {
- OSErr status = PrNewHandle(h, size);
- if (status == noErr)
- memset(**h, 0, size);
-
- return status;
- }
-
- OSErr PrSetHandleSize(Handle h, long newSize)
- {
- OSErr status;
- SetHandleSize(h, newSize);
- status = MemError();
- return status;
- }
-
-
- /**
- Wrapper for GetResource that returns an error.
- **/
- OSErr FetchResource(OSType resType, short ID, Handle *h)
- {
- OSErr status;
- *h = GetResource(resType, ID);
- if (*h != nil) {
- status = noErr;
- } else {
- status = ResError();
- if (status == noErr)
- status = MemError();
- if (status == noErr)
- status = resNotFound;
- }//end if
-
- return status;
-
- }
-
- /**
- Wrapper for NewPtr that returns an error
- **/
- OSErr PrNewPtr(Ptr *p, long size)
- {
- OSErr status;
- *p = NewPtr(size);
- status = MemError();
- return status;
- }
-
-
- /*******************************************************
- Function: MakeMac8BitEncoding:
-
- Function sets up an encoding vector for the standard
- Mac 8 bit encoding for the current active script system.
-
- theFont: the font to make encoding for.
- encoding: array of 256 shorts, encoding will be returned
- in here.
-
- returns: The number of bytes encoded. (should always be 256)
-
- ********************************************************/
- long MakeMac8BitEncoding(gxFont theFont, unsigned short encoding[])
- {
- gxFontScript theScript;
- long index;
- unsigned char theBytes[256];
- unsigned char *aByte;
- long length;
- short i;
-
- theScript = (gxFontScript)GetScriptManagerVariable(smSysScript) + 1; // gx graphic scripts are 1+scriptmgr scripts.
-
- if( ! ( index = GXFindFontEncoding(theFont, gxMacintoshPlatform, theScript, gxNoLanguage) ) )
- {
- index = GXFindFontEncoding(theFont, gxMacintoshPlatform, gxRomanScript, gxNoLanguage);
- }
-
-
- aByte = theBytes;
- for (i = 0; i < 256; ++i)
- *aByte++ = i;
-
- length = GXApplyFontEncoding(theFont, index, nil, theBytes, 256, encoding, nil);
-
- return(length);
-
- }//MakeMac8BitEncoding
-
-